package com.ef.util;

import java.io.File;
import java.io.IOException;
import java.lang.reflect.Field;
import java.util.List;

import jxl.Workbook;
import jxl.format.Colour;
import jxl.format.UnderlineStyle;
import jxl.write.Label;
import jxl.write.WritableCellFormat;
import jxl.write.WritableFont;
import jxl.write.WritableSheet;
import jxl.write.WritableWorkbook;
import jxl.write.WriteException;
import jxl.write.biff.RowsExceededException;

/**
 * 当前支持jxl版本2.6.9
 * 
 * @author jsper
 * @version 1.0 createDate 2010-1-16
 * 
 */
public class ExcelUtils<T> {

	protected T domain;
	protected Class<T> domainClass;
	public boolean useDefaultTitle = true;
	public boolean useDefaultSheetName = true;
	
	public static final WritableFont style1 = new WritableFont(
			WritableFont.ARIAL, 16, WritableFont.BOLD, false,
			UnderlineStyle.NO_UNDERLINE, Colour.YELLOW);

	public void exportAsOut(List<T> data, File targetFile) throws IOException,
			RowsExceededException, WriteException {

		if (!targetFile.exists()) {
			targetFile.mkdirs();
		}
		WritableWorkbook wwb = Workbook.createWorkbook(targetFile);
		WritableSheet sheet = wwb.createSheet("Sheet 1", 0);

		Field[] fs = data.getClass().getDeclaredFields();

		//write title;
		for (int i = 0; i < fs.length; i++) {
			Label title = new Label(i, 0,
					fs[i].toGenericString().toUpperCase(),
					new WritableCellFormat(style1));
			sheet.addCell(title);
		}
		
		for(int j= 0;j<data.size();j++){
			
			 
		}

	}

}
